package com.itheima.controller;


import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MessageController {
    private final StreamBridge streamBridge;
    public MessageController(StreamBridge streamBridge) {
        this.streamBridge = streamBridge;
    }
    @GetMapping("/data")
    public String sendData(String msg) {
        Message<String> streamMessage = MessageBuilder
                .withPayload(msg)
                .setHeader("partitionKey", msg)
                .build();
        streamBridge.send("handleMessage-out-0",streamMessage);
        return "send SUCCESS";
    }
}